FROM python:3.11-slim

WORKDIR /app

# 安装系统依赖
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*

# 复制依赖文件并安装
COPY requirements/gateway.txt requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

# 复制配置和应用代码
COPY config ./config
COPY ./api_gateway/app.py .
COPY ./api_gateway/config.py .

# 设置环境变量
ENV PORT=8002
ENV PYTHONPATH=/app

# 暴露端口
EXPOSE 8002

# 健康检查
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
    CMD curl -f http://localhost:8002/ || exit 1

# 启动应用
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8002"]